@echo off
chcp 65001 >nul

:: 参数处理
set verbose=1
if "%~1"=="/s" set verbose=0

:: 检查MAVEN_HOME是否已设置
if %verbose% equ 1 echo 正在检查MAVEN_HOME环境变量...
if defined MAVEN_HOME (
    if %verbose% equ 1 echo MAVEN_HOME已设置为: %%MAVEN_HOME%%
    goto check_path
) else (
    if %verbose% equ 1 echo MAVEN_HOME环境变量未设置
)

:: 设置MAVEN_HOME
set MAVEN_HOME="%cd%\apache-maven-3.9.6"
setx MAVEN_HOME %MAVEN_HOME%
if %verbose% equ 1 echo 已设置MAVEN_HOME: %MAVEN_HOME%

:check_path
:: 检查PATH是否已包含Maven路径
if %verbose% equ 1 echo 正在检查PATH环境变量...
if %verbose% equ 1 echo 当前PATH值: %%PATH%%
echo %%PATH%% | find "%%MAVEN_HOME%%\bin" >nul
if %errorlevel% equ 0 (
    if %verbose% equ 1 echo PATH中已包含Maven路径: %%MAVEN_HOME%%\bin
    goto end
) else (
    if %verbose% equ 1 echo PATH中未找到Maven路径
)

:: 添加Maven路径到PATH
if %verbose% equ 1 echo 正在将Maven路径添加到PATH...
setx PATH "%%PATH%%;%%MAVEN_HOME%%\bin"
if %verbose% equ 1 echo 已将Maven路径添加到PATH: %%MAVEN_HOME%%\bin
if %verbose% equ 1 echo 更新后的PATH值: %%PATH%%

:: 立即更新当前会话的环境变量
set PATH=%%PATH%%;%%MAVEN_HOME%%\bin

:end